package com.controller;

import com.model.Product;
import com.page.GenericPage;
import com.po.AdvertisementPO;
import com.po.ProductModifyPO;
import com.po.ProductPO;
import com.po.ProductQueryPO;
import com.result.Result;
import com.service.ProductService;
import com.vo.AdvertisementVO;
import com.vo.ProductQueryBySnVo;
import com.vo.ProductVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: chihaojie
 * @Date: 2019/5/29 14:11
 * @Version 1.0
 * @Note
 */


@Api(value = "productApi")
@CrossOrigin
@RestController
@RequestMapping("/product")
public class ProductController {


    @Autowired
    private ProductService  productService;

    //ProductVO
    @ApiOperation(value = "保存", httpMethod = "POST", notes = "保存")
    @RequestMapping(value = "/save", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<Product> save(@RequestBody ProductPO productPO) {
        return productService.save(productPO);
    }


    //ProductVO
    @ApiOperation(value = "删除", httpMethod = "GET", notes = "删除")
    @RequestMapping(value = "/removeById", method = RequestMethod.GET)
    public Result<Boolean> removeById(@RequestParam Long  id) {
        return productService.removeById(id);
    }


    //ProductVO
    @ApiOperation(value = "修改", httpMethod = "POST", notes = "修改")
    @RequestMapping(value = "/modifyById", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<Boolean> modifyById(@RequestBody ProductModifyPO productModifyPO) {
        return productService.modifyById(productModifyPO);
    }

    @ApiOperation(value = "查询", httpMethod = "GET", notes = "查询")
    @RequestMapping(value = "/queryById", method = RequestMethod.GET)
    public Result<Product> queryById(@RequestParam Long  id) {
        return productService.queryById(id);
    }


    //ProductVO
    @ApiOperation(value = "查询", httpMethod = "POST", notes = "查询")
    @RequestMapping(value = "/queryAll", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<GenericPage<Product>> queryAll(@RequestBody ProductQueryPO productQueryPO) {
        return productService.queryAll(productQueryPO);
    }


    @ApiOperation(value = "根据SN查询", httpMethod = "GET", notes = "根据SN查询")
    @RequestMapping(value = "/queryBySn", method = RequestMethod.GET)
    public Result<List<ProductQueryBySnVo>> queryBySn(@RequestParam String  sn) {
        return productService.queryBySn(sn);
    }

}
